*12345678901234567890123456789012345678901234567890123456789012345678901234567890

capture log close
clear
clear matrix
set mem 500m
set more off

#delimit ;

*log using "C:\Documents and Settings\James\Desktop\my dropbox\PTAs\BacciniData\baccini_prelim.log", 
replace;

*	************************************************************************ *;
* 	File-Name: Table4Figure1.do												 *;
*	Date:  10/24/09															 *;
*	Author: 	James Hollyer                                                *;
*	Purpose:   To run a series of preliminary survival analyses using the    *;
*	Baccini data merged with Archigos.									 	 *;
*	Data Input: baccini_survival2.dta										 *;
*	************************************************************************ *;

use "c:\documents and settings\james\desktop\my dropbox\PTAs\HollyerRosendorffReplicationMaterials\baccini_survival2.dta";

stset endobs, id(leadid) fail(fail==1) origin(eindate) enter(time mdy(1,1,1995))
scale(365.25);

*	************************************************************************ *;
*	The following will generate a variable 									 *;
*	log_num_pta_sign=ln(num_pta_lead_sign+1)								 *;
*	************************************************************************ *;

gen log_num_pta_sign=.;
replace log_num_pta_sign=ln(num_pta_lead_sign+1);


*	************************************************************************ *;
*	The following will add the interaction of pta_lead_sign and polity2 to 	 *;
*	the model.  The results of these models are reported in Table 4 of the   *;
*	paper.  The graphs of the hazard rates produced below are reproduced as  *;
*	Figure 1 in the paper.													 *;
*	************************************************************************ *;

gen pta_sign_dem = pta_lead_sign*polity2;
gen pta_num_dem = log_num_pta_sign*polity2;

stcox  log_num_pta_sign polity2 pta_num_dem rgdpch openk grgdpch, 
tvc(log_num_pta_sign polity2 pta_num_dem) shared(ccode) nohr;

est2vec PTA_num_surv, replace name(Model1);

stcox  log_num_pta_sign polity2 pta_num_dem rgdpch openk grgdpch, shared(ccode) nohr;

est2vec, addto(PTA_num_surv) name(Model2);

estat phtest, rank detail;

sum log_num_pta_sign;

local max_log_pta=r(max);
local max_pta_min_polity=`max_log_pta'*-10;
local max_pta_max_polity=`max_log_pta'*10;

stcurve, hazard at1(polity2=-10  log_num_pta_sign=0  pta_num_dem=0) 
at2(polity2=-10 log_num_pta_sign=0.693 pta_num_dem=-6.93) 
at3(polity2=-10 log_num_pta_sign=`max_log_pta' pta_num_dem = `max_pta_min_polity')
graphregion(fcolor(white)) ytitle(Hazard Rate) xtitle(Years in Office) 
scheme(s2mono) legend(label(1 No PTA) label(2 One PTA) label(3 Max PTAs)) 
name(minpolity, replace) subtitle(Minimum Polity Score);

stcurve, hazard at1(polity2=10  log_num_pta_sign=0  pta_num_dem=0) 
at2(polity2=10 log_num_pta_sign=0.693 pta_num_dem=6.93) 
at3(polity2=10 log_num_pta_sign=`max_log_pta' pta_num_dem =`max_pta_max_polity')
graphregion(fcolor(white)) ytitle(Hazard Rate) xtitle(Years in Office) 
scheme(s2mono) legend(label(1 No PTA) label(2 One PTA) label(3 Max PTAs)) 
name(maxpolity, replace) subtitle(Maximum Polity Score);

*graph combine minpolity maxpolity, ycommon graphregion(fcolor(white))
title(Estimated Hazard Rates);

*graph export "c:\documents and settings\james\desktop\collaboration with peter\naivemfx.png",
replace;

stcox  log_num_pta_sign polity2 rgdpch openk grgdpch, 
tvc(log_num_pta_sign polity2) shared(ccode) nohr;

est2vec, addto(PTA_num_surv) name(Model3);

stcox  log_num_pta_sign polity2 rgdpch openk grgdpch, shared(ccode) nohr;

est2vec, addto(PTA_num_surv) name(Model4);

*est2tex PTA_num_surv, preserve path("c:\documents and settings\james\desktop\collaboration with peter\") 
mark(stars) dot replace;

 
*	************************************************************************ *;
*	The following will close the log file.									 *;
*	************************************************************************ *;

log close;
